package com.twd.nio;

import java.nio.ByteBuffer;

/**
 * @author: twd
 * @since: 2023/6/5 10:17
 */
public class IODemo {
    public static void main(String[] args) {
        //byte[] b = new byte[]{ 1,2,3,4,5,6};
        ByteBuffer byteBuf = ByteBuffer.allocate(3);
        byteBuf.put((byte) 1);
        byteBuf.put((byte) 2);
        byteBuf.put((byte) 3);
        System.out.println(byteBuf.toString());
        ByteBuffer byteBuf2 = ByteBuffer.allocate(32);

        //这里一定要切换成读模式
        byteBuf.flip();
        System.out.println(byteBuf.toString());
        byteBuf2 = byteBuf2.put(byteBuf);
        byteBuf2.put((byte)4);
        byteBuf2.flip();

        System.out.println(byteBuf2.get());
        System.out.println(byteBuf2.get());
        System.out.println(byteBuf2.get());
        System.out.println(byteBuf2.get());
    }

}
